import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * 值集 值集视图
 * @creationDate 2019/12/25
 */
import request from "../../utils/request";
import { getEnvConfig } from "../../utils/iocUtils";
import { getCurrentOrganizationId, isTenantRoleLevel } from "../../utils/utils";

var _getEnvConfig = getEnvConfig(),
    CPAAS_PLATFORM = _getEnvConfig.CPAAS_PLATFORM;
/**
 * 统一查询独立、SQL、URL类型的值集
 * {CPAAS_PLATFORM}/v1/lovs/data
 * @param {String} lovCode - 值集code
 * @param {Object} params - 额外的查询参数
 */


export function queryUnifyIdpValue(_x) {
  return _queryUnifyIdpValue.apply(this, arguments);
}
/**
 * 查询单个独立值集值
 * {CPAAS_PLATFORM}/v1/lovs/value
 * @param {String} lovCode
 */

function _queryUnifyIdpValue() {
  _queryUnifyIdpValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(lovCode) {
    var params,
        _args = arguments;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            params = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(isTenantRoleLevel() ? "".concat(getCurrentOrganizationId(), "/") : '', "lovs/data"), {
              query: _objectSpread({
                lovCode: lovCode
              }, params)
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryUnifyIdpValue.apply(this, arguments);
}

export function queryIdpValue(_x2) {
  return _queryIdpValue.apply(this, arguments);
}
/**
 * 批量查询独立值集值
 * {CPAAS_PLATFORM}/v1/lovs/value/batch
 * @param {Object} params
 * @example queryMapIdpValue({ level: 'CPFM.LEVEL', dir: 'CPFM.DIRECTION' })
 */

function _queryIdpValue() {
  _queryIdpValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(lovCode) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(isTenantRoleLevel() ? "".concat(getCurrentOrganizationId(), "/") : '', "lovs/value"), {
              query: {
                lovCode: lovCode
              }
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _queryIdpValue.apply(this, arguments);
}

export function queryMapIdpValue(_x3) {
  return _queryMapIdpValue.apply(this, arguments);
} // 没有用到的 api 先注释
// /**
//  * 根据父值集值查询子值集值
//  * {CPAAS_PLATFORM}/v1/lovs/value/parent-value
//  * @param {Object} params
//  * @param {String} params.lovCode 子值集编码
//  * @param {String} params.parentValue 父值集值
//  */
// export async function queryParentIdpValue(params) {
//   return request(`${CPAAS_PLATFORM}/v1/lovs/value/parent-value`, {
//     query: params,
//   });
// }
// 没有用到的 api 先注释
// /**
//  * 根据 tag 获取值集值
//  * {CPAAS_PLATFORM}/v1/lovs/value/tag
//  * @param {Object} params
//  * @param {String} params.lovCode 值集编码
//  * @param {String} params.tag tag
//  */
// export async function queryTagIdpValue(params) {
//   return request(`${CPAAS_PLATFORM}/v1/lovs/value/tag`, {
//     query: params,
//   });
// }

function _queryMapIdpValue() {
  _queryMapIdpValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(isTenantRoleLevel() ? "".concat(getCurrentOrganizationId(), "/") : '', "lovs/value/batch"), {
              query: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _queryMapIdpValue.apply(this, arguments);
}